<?php
/**
 * PublicController.class.php
 * 公共控制器
 * 
 * @author  王中艺 <wangzy_smile@qq.com>
 * @date    2017-08-25
 */

namespace Attach\Controller;

class PublicController extends BaseController {

    /**
     * 当前用户信息获取
     * @return  $userInfo
     */
    function getUserInfo(){
        if(!$this->userId){
            $this->response('未登录', -502);
        }
        $this->response(['info' => $this->userInfo]);
    }

    /**
     * 退出登录
     */
    function logout(){
        session('user_id', null);
        $this->response();
    }

    /**
     * 菜单列表获取
     * @return  $list
     */
    function getMenuList(){
        if(!$this->userId){
            $this->response('未登录', -502);
        }

        $menuList[]     = [
            'id'    => 1,
            'title' => '会员管理',
            'icon'  => 'fa fa-user',
            'child' => [
                [
                    'title' => '会员列表',
                    'url'   => 'User/getList',
                    'icon'  => 'fa fa-user',
                    'id'    => 11
                ],[
                    'title' => 'VIP列表',
                    'url'   => 'User/getVipList',
                    'icon'  => 'fa fa-user',
                    'id'    => 12
                ]
            ]
        ];

        if(in_array($this->userInfo['role_id'], [101, 102, 103])){
            $menuList[]     = [
                'id'    => 2,
                'title' => '销售记录',
                'icon'  => 'fa fa-calendar',
                'child' => [[
                        'title' => '分成列表',
                        'url'   => 'Deduct/getList',
                        'id'    => 21,
                    ]
                ]
            ];
        }

        if(in_array($this->userInfo['role_id'], [101])){
            $menuList[]     = [
                'id'    => 3,
                'title' => '提现审核',
                'icon'  => 'fa fa-list-alt',
                'child' => [[
                        'title' => '提现列表',
                        'url'   => 'Withdraw/getList',
                        'id'    => 31
                    ],
                ],
            ];
        }    

        $this->response(['list' => $menuList]);
    }

    function debug(){
        
    }
}